#include <iostream>
#include <string>
#include <ctime>
#include "swarmSocketServer.h"
#include "swarmSocketClient.h"

using namespace std;

int main()
{
	system("fuser -k -n tcp 5555");
	time_t begin, now;
	time(&begin);
	swarmSocketServer serve(5555, false);
	vector< vector<string> > ms;
	while(ms.size() == 0)
	{
		ms = serve.read();
	}
	time(&begin);
	ms = serve.read();
	time(&now);
	cout << "default read " << difftime(now, begin)  << endl;
	for(int i = 0; i < ms.size(); i++)
	{
		for(int j = 0; j < ms[i].size();j++)
		{
			cout << ms[i][j] << " ";
		}
		cout << endl;
	}
	time(&begin);
	ms = serve.read(5);
	time(&now);
	cout << "read 5 " << difftime(now, begin)  << endl;
	for(int i = 0; i < ms.size(); i++)
	{
		for(int j = 0; j < ms[i].size();j++)
		{
			cout << ms[i][j] << " ";
		}
		cout << endl;
	}
	time(&begin);
	ms = serve.read(-1);
	time(&now);
	cout << "read -1 " << difftime(now, begin)  << endl;
	for(int i = 0; i < ms.size(); i++)
	{
		for(int j = 0; j < ms[i].size();j++)
		{
			cout << ms[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}
